const orderModel = require('../model/orderModel');

//新增
module.exports.create = async function (obj) {
  return await orderModel.create(obj);
};

//查询
module.exports.find = async function (page, searchParams) {
  let { current, pageSize } = page;
  //根据查询条件获取总数
  let total = await orderModel.countDocuments(searchParams);
  //根据查询条件获取具体数量的数据
  let data = await orderModel
    .find(searchParams)
    .limit(pageSize)
    .skip((current - 1) * pageSize);
  return { current, pageSize, total, rows: data };
};

//删除
module.exports.delete = async function (id) {
  return await orderModel.deleteOne({ _id: id });
};
